import { selectAreaPromise } from './select_area'
document.addEventListener('DOMContentLoaded', () => {
    console.log('DOMContentLoaded');
});

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
    console.log(message, sender, 'content_script收到消息')
    switch (message.action) {
        case 'SELECT_SCREEN_AREA': {
            return selectAreaPromise({
                done: (rect: any, boundingRect: any) => {
                    console.log('SELECT_SCREEN_AREA  - selectArea', rect, boundingRect);
                    sendResponse({
                        action: 'CS_SCREEN_AREA_SELECTED',
                        rect: {
                            x: boundingRect.x,
                            y: boundingRect.y,
                            width: boundingRect.width,
                            height: boundingRect.height,
                        },
                        devicePixelRatio: window.devicePixelRatio,
                    })
                },
            });
        }
    }
    return true
})